Auto Filter Last updated: 2024-03-26

Starting from version 1.1.54, you can now add a direct filter through the ready-made elements within your resource in the 'fields' method.

Once you execute the method ->f() or ->filter() or ->addToFilter() or ->showInFilter(), Dash will immediately understand that you want to assign this element to the filter list of the dataTable at index page of Resource.

Dropdown menus such as belongsTo and select, and even fields like flat picker or fields that hold date and time, are allowed to be one of the filtering elements.

An example of this is:

fullDateTime()->make('DateTime', 'created_at')->filter(),
//or
fullDateTime()->make('DateTime', 'created_at')->f(),
//or
fullDateTime()->make('DateTime', 'created_at')->addToFilter(),
//or
fullDateTime()->make('DateTime', 'created_at')->showInFilter(),

Additionally, you can also directly use the methods with:

belongsTo(__('main.user'), 'user', Users::class)->f(),
// or
belongsTo(__('main.user'), 'user', Users::class)->filter(),
// or
belongsTo(__('main.user'), 'user', Users::class)->addToFilter(),
// or
belongsTo(__('main.user'), 'user', Users::class)->showInFilter(),

// or with select element 
 select(__('main.status'),'status')->options([
                'pending'=>__('main.pending'),
                'done'=>__('main.done'),
                'reject'=>__('main.reject'),
            ])->filter() // etc...

 

Please note that the following types cannot be used with this method as they are not logically suitable for it: 'text', 'textarea', 'file', 'image', 'dropzone', 'ckeditor', 'hasManyThrough', 'hasMany', 'belongsToMany', 'morphToMany', 'morphedByMany', 'morphMany', 'audio', 'video', 'morphTo'.

Since 'text' and 'textarea' represent textual data that can be searched using the search engine of the dataTable itself, you can set the search within them using the $search array inside the resource.
 

You can also control the display of the element within Bootstrap 5 by setting appropriate parameters. For example, this can be applied to the rest of the methods as follows:


->f(true,['column'=>6])
// or
->filter(true,['column'=>6]) // etc ..

Note that the columns range from 1 to 12 in Bootstrap.
 


When using dates in the range or multiple styles:


fullDateTime()->make('DateTime', 'created_at')->enableTime(false)->modeDates("range")->f(), 

 

 

Ensure that the delimiters are in the form of this symbol: (,)

Meaning, do not assign any values to the field like:


fullDateTime()->make('DateTime', 'date')->modeDates("multiple")->conjunction("::")
 

Instead, make it like this:

 


fullDateTime()->make('DateTime', 'date')->modeDates("multiple")->conjunction(",")
 

Or, do not assign the conjunction method at all, and it will automatically set the comma as the delimiter.